package com.ruoyi.evaluate.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.evaluate.domain.EvaluateProject;
import com.ruoyi.evaluate.service.IEvaluateProjectService;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评价项目Controller
 * 
 * @author yepanpan
 * @date 2020-11-09
 */
@Api("评价项目信息管理")
@RestController
@RequestMapping("/evaluate/evalProject")
public class EvaluateProjectController extends BaseController
{
    @Autowired
    private IEvaluateProjectService evaluateProjectService;

    /**
     * 查询评价项目列表
     */
    @ApiOperation("获取评价项目列表")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:list')")
    @GetMapping("/list")
    public TableDataInfo list(EvaluateProject evaluateProject)
    {
        startPage();
        evaluateProject.getParams().put("year", ServletUtils.getParameter("year"));
        evaluateProject.getParams().put("specId", ServletUtils.getParameter("specId"));
        List<EvaluateProject> list = evaluateProjectService.selectEvaluateProjectList(evaluateProject);
        return getDataTable(list);
    }

    /**
     * 导出评价项目列表
     */
    @ApiOperation("导出评价项目列表")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:export')")
    @Log(title = "评价项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EvaluateProject evaluateProject)
    {
        List<EvaluateProject> list = evaluateProjectService.selectEvaluateProjectList(evaluateProject);
        ExcelUtil<EvaluateProject> util = new ExcelUtil<EvaluateProject>(EvaluateProject.class);
        return util.exportExcel(list, "evalProject");
    }

    /**
     * 获取评价项目详细信息
     */
    @ApiOperation("获取评价项目详细信息")
    @ApiImplicitParam(name = "id", value = "评价项目ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(evaluateProjectService.selectEvaluateProjectById(id));
    }

    /**
     * 新增评价项目
     */
    @ApiOperation("新增评价项目")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:add')")
    @Log(title = "评价项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EvaluateProject evaluateProject)
    {
        return toAjax(evaluateProjectService.insertEvaluateProject(evaluateProject));
    }

    /**
     * 修改评价项目
     */
    @ApiOperation("修改评价项目")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:edit')")
    @Log(title = "评价项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EvaluateProject evaluateProject)
    {
        return toAjax(evaluateProjectService.updateEvaluateProject(evaluateProject));
    }
    

    /**
     * 删除评价项目
     */
    @ApiOperation("删除评价项目")
    @ApiImplicitParam(name = "id", value = "评价项目ID", required = true, dataType = "int", paramType = "path")
    @PreAuthorize("@ss.hasPermi('evaluate:evalProject:remove')")
    @Log(title = "评价项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(evaluateProjectService.deleteEvaluateProjectByIds(ids));
    }
}
